<template>
  <div class="list" ref="wrapper">
    <div>
      <div class="locatBody_box">
        <h3>热门城市</h3>
        <div class="locatBody_box_item">
          <div
            class="locatBody_box_item_on"
            v-for="(item,index) in ALLhotCities"
            :key="index"
            @click="handleCityClick(item.name)"
          >{{item.name}}</div>
        </div>
      </div>

      <!--字母排序  -->
      <div class="locatBody_box">
        <h3>字母排序</h3>
        <div class="locatBody_box_item">
          <div class="locatBody_box_item_zm" v-for="(item,index) in letter" :key="index">{{item}}</div>
        </div>
      </div>

      <!-- 城市字母 -->
      <div class="locatBody_box" v-for="(item,index) in cities" :key="index" :ref="index">
        <h3>{{index}}</h3>
        <div class="locatBody_box_item">
          <div
            class="locatBody_box_item_cs"
            v-for="i in item"
            :key="i.id"
            @click="handleCityClick(i.name)"
          >{{i.name}}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Bscroll from "better-scroll";
export default {
  props: {
    ALLhotCities: Array,
    letter: Array,
    cities: Object,
    val: String,
  },
  mounted() {
    this.scroll = new Bscroll(this.$refs.wrapper, {
      click: true,
    });
  },
  watch: {
    val() {
      // console.log(this.val);
      if (this.val) {
        const element = this.$refs[this.val][0];
        this.scroll.scrollToElement(element);
      }
    },
  },
  methods: {
    handleCityClick(kewVal) {
      this.$store.dispatch("changCity", kewVal);
      this.$router.push("/");
      localStorage.setItem('city',kewVal)
    },
  },
};
</script>

<style  scoped>
.locatBody_box_item {
  /* width: 100%; */
  display: flex;
  flex-wrap: wrap;
}
.list {
  width: 100%;
  height: 667px;
  overflow: auto;
}
.locatBody_box_item_on {
  box-sizing: border-box;
  width: 33.3%;
  line-height: 0.9rem;
  text-align: center;
  border: 1px solid #cdcd;
}
h3 {
  font-size: 0.24rem;
  padding: 0.24rem 0.3rem;
  font-weight: 400;
  background: rgb(243, 243, 243);
}
.locatBody_box_item_zm {
  width: 16.6%;
  box-sizing: border-box;
  line-height: 0.9rem;
  text-align: center;
  /* border: 1px solid #CDCD; */
}
.locatBody_box_item_cs {
  width: 25%;
  box-sizing: border-box;
  line-height: 0.9rem;
  text-align: center;
  border: 1px solid rgb(243, 243, 243);
}
</style>